package com.base.api.cdr;

import com.base.api.pms.PmsPublicSqlQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @author wnhuang
 * @Package com.base.api.cdr
 * @date 2020-12-31 22:34
 */
@Component
public class ClinicalDiagnosis extends PmsPublicSqlQuery {

    @Override
    public String splicSql(String sql, Map<String, Object> param){
        StringBuilder param1 = new StringBuilder();
        if(param != null){
            if(param.get("patientId") != null && !StringUtils.isBlank((String) (param.get("patientId")))){
                param1.append(" and patient_id = '" + param.get("patientId") + "'");
            }
            if(param.get("visitNumber") != null && !StringUtils.isBlank((String) (param.get("visitNumber")))){
                param1.append(" and patient_visit_id = '" + param.get("visitNumber") + "'");
            }

            if(param.get("MedicalType") != null){
                param1.append(" and PATIENT_VISIT_TYPE in( " + Arrays.toString(((ArrayList<Integer>)(param.get("MedicalType"))).toArray()).replace("[","").replace("]","") + ")");
            }

        }
        return MessageFormat.format(sql.replace("'", "''"), param1.toString());
    };
}
